{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "%matplotlib inline"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Confusion Matrix"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Functions for generating confusion matrices."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "> `from mlxtend.evaluate import confusion_matrix`    \n",
    "> `from mlxtend.plotting import plot_confusion_matrix`"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Overview"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Confusion Matrix"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The *confusion matrix* (or *error matrix*) is one way to summarize the performance of a classifier for binary classification tasks. This square matrix consists of columns and rows that list the number of instances as absolute or relative \"actual class\" vs. \"predicted class\" ratios.\n",
    "\n",
    "\n",
    "Let $P$ be the label of class 1 and $N$ be the label of a second class or the label of all classes that are *not class 1* in a multi-class setting."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "![](./confusion_matrix_files/confusion_matrix_1.png)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### References\n",
    "\n",
    "- -"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 1 - Binary classification"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[3, 1],\n",
       "       [2, 2]])"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "from mlxtend.evaluate import confusion_matrix\n",
    "\n",
    "y_target =    [0, 0, 1, 0, 0, 1, 1, 1]\n",
    "y_predicted = [1, 0, 1, 0, 0, 0, 0, 1]\n",
    "\n",
    "cm = confusion_matrix(y_target=y_target, \n",
    "                      y_predicted=y_predicted)\n",
    "cm"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "To visualize the confusion matrix using matplotlib, see the utility function [`mlxtend.plotting.plot_confusion_matrix`](../plotting/plot_confusion_matrix):"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAPkAAAD+CAYAAAD4SqMoAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAAPYQAAD2EBqD+naQAAEhxJREFUeJzt3XmUXGWdxvHvQxKMSQSMSNhCFiAgowSCmhMHCAhziFEC\njCICQ9SIG/t+hOBkBESEmAzLMAgIRIkDDiJkzkRAMCooy2ELMIEAJgFExBDD1knI9ps/7m2sFJ3Q\nXX2rbvVbz+ecOl33vW/d+nVVP31vvVX1XkUEZpaujcouwMzqyyE3S5xDbpY4h9wscQ65WeIccrPE\nOeRmiXPIzRLXu+wCukrSB4ADgEXAinKrMStNX2AocHtELNlQxx4XcrKAzyy7CLMmcSTw0w116Ikh\nXwRw2tnfY/CQYSWX0rrG7LZj2SW0tKeeepKJR/0L5HnYkJ4Y8hUAg4cMY4cRu5RdS8saNeojZZdg\nmXd9yeqBN7PEOeRmiXPIzRLnkJslziE3S5xDbpY4h9wscQ65WeIccrPEOeRmiXPIzRLnkJslziE3\nS5xDbpY4h9wscQ65WeIccrPEOeRmiXPIzRLnkJslziE3S5xDbpY4h9wscQ65WeIccrPEOeRmiXPI\nzRLnkJslziE3S5xDbpY4h9wscQ65WeIccrPEOeRmiXPIzRLnkJslziE3S5xDbpY4h9wscU0TcknH\nSlooabmk+yR9rOyaijT71p9x3KTPcej4T3Do+E9w6jFH8eD995RdVsu5++67OfigCWw3eBv69N6I\n/5k1q+yS6q4pQi7pMOAHwBRgd2AucLukzUstrECbb7ElX/r6SVxy1Y1cfOUNjBz1cc6dfCLPL1pQ\ndmktpa2tjZG77cZll12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4r14/NtLQN+Qxbydxt4W8O6o+sXAH8lO1T/KXAC2Yyq7eunkB3hfD2vvw24Adi0\nartfyPstzx/vOcBB+boh+f0mPfDmiRwbSNIc4JGI6MprS7Nu8eG6WeIc8sbyYZM1nA/XzRLnPblZ\n4hxys8Q55GaJc8jNEueQmyXOITdLnENuljiH3CxxDrlZ4v4fUA+dJCME/lMAAAAASUVORK5CYII=\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0x106072278>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "import matplotlib.pyplot as plt\n",
    "from mlxtend.plotting import plot_confusion_matrix\n",
    "\n",
    "fig, ax = plot_confusion_matrix(conf_mat=cm)\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 2 - Multi-class classification"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[2, 1, 0, 0],\n",
       "       [1, 2, 0, 0],\n",
       "       [0, 0, 1, 0],\n",
       "       [0, 0, 0, 1]])"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "from mlxtend.evaluate import confusion_matrix\n",
    "\n",
    "y_target =    [1, 1, 1, 0, 0, 2, 0, 3]\n",
    "y_predicted = [1, 0, 1, 0, 0, 2, 1, 3]\n",
    "\n",
    "cm = confusion_matrix(y_target=y_target, \n",
    "                      y_predicted=y_predicted, \n",
    "                      binary=False)\n",
    "cm"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "To visualize the confusion matrix using matplotlib, see the utility function [`mlxtend.plotting.plot_confusion_matrix`](../plotting/plot_confusion matrix):"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAPkAAAD+CAYAAAD4SqMoAAAABHNCSVQIC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2rxfhnSwicaugxSt4r3oX8/edbPE+8f+N\n39m1Ga/Mvdxnn9HkT8DIhGmpnpxiMLDdOXd3ywRJvduY71RJ3eNezQfjFfg159y7kv4GnOGce6ad\ndUX+EJrtXc+9UyXdJ+ksSeOBG/BOItCep/B2qj0n6QJJvSVdImmRpC/48ywC/l3SFZL64I1b3vmz\nFuicewN4AnjUv09v/0MrY/xZ3sArwEhJXSR19J9g7gMWSrpW0umSzpV0g6Sv+/f7Md5bi3v8x3gN\nMDHF/6PX/f+nq/113Ii30yzRfuBxSf0lXej/Hyx1zr3r3z4LuF3SFElflPRlSZMkTY1bRuQPoYW+\nU+BIuuDt+LofeBDvfWEDMDdhnq3AjW3ctxuwBO+MLk14Rfgx0Mm/vQhvr/0eYDdwrz9//I63Wlrv\nXT8ar7Rv4m2+bwEmxt0+E2+z/CDwaNz0KXiv6h/jjUm/DLgg7vYR/rKagN/hlfxwO96aab13/W68\n86DtBX4G3Ig36mzL7bPwtnC+5edvBJ4BShKWO86fb5///70KuMK/rZe/3kjveLOBHHNI0ipgo3Mu\nlfeWxqTFNteNiTgreW7ZZpPJOdtcNybi7JXcmIizkhsTcVZyYyLOSm5MxFnJjYk4K7kxEWclNybi\nrOTGRJyV3JiI+19MzjwBUnxJJwAAAABJRU5ErkJggg==\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0x10eabf8d0>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "import matplotlib.pyplot as plt\n",
    "from mlxtend.evaluate import confusion_matrix\n",
    "\n",
    "fig, ax = plot_confusion_matrix(conf_mat=cm)\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 3 - Multi-class to binary"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "By setting `binary=True`, all class labels that are not the positive class label are being summarized to class 0. The positive class label becomes class 1."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[4, 1],\n",
       "       [1, 2]])"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import matplotlib.pyplot as plt\n",
    "from mlxtend.evaluate import confusion_matrix\n",
    "\n",
    "y_target =    [1, 1, 1, 0, 0, 2, 0, 3]\n",
    "y_predicted = [1, 0, 1, 0, 0, 2, 1, 3]\n",
    "\n",
    "cm = confusion_matrix(y_target=y_target, \n",
    "                      y_predicted=y_predicted, \n",
    "                      binary=True, \n",
    "                      positive_label=1)\n",
    "cm"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "To visualize the confusion matrix using matplotlib, see the utility function [`mlxtend.plotting.plot_confusion_matrix`](../plotting/plot_confusion matrix):"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAPkAAAD+CAYAAAD4SqMoAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAAPYQAAD2EBqD+naQAAEidJREFUeJzt3XmUVOWdxvHvY4MSQHGI4xLTLIqiniiIiQxG0yrOkXFB\nnbghI+5O4oYbnjHqkKPH0bjghiZxAYn7EoNojLgmonE5uBANiCK4R0VF0AaU5Z0/7m1SlA10V9+q\nW/3W8zmnTtd971K/rtNP33vfqvtehRAws3itlXcBZlZeDrlZ5Bxys8g55GaRc8jNIueQm0XOITeL\nnENuFrkOeRfQWpK+C+wJvA0szrcas9x0AnoBk0MIn61uwXYXcpKA35Z3EWZVYjhw++oWaI8hfxvg\nzHMvor5n75xLqV2D+m+Rdwk17fXXZzDi8P+CNA+r0x5Dvhigvmdv+my5Td611KwBA7bNuwRLrPGU\n1R1vZpFzyM0i55CbRc4hN4ucQ24WOYfcLHIOuVnkHHKzyDnkZpFzyM0i55CbRc4hN4ucQ24WOYfc\nLHIOuVnkHHKzyDnkZpFzyM0i55CbRc4hN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bTCE8A7wO2Bcuk6v9Esr\nB6WLvEMSgH0lbSCpS/oP5jLgCkkjJG0maXtJJ0k6PF3vNySnFpekv+NhwBGtfI/eTN+nQ9LXOIWk\n06zY18AESdtJ2iV9D+4KIcxN548GzpZ0sqQtJP1A0pGSTi3YRvQfoeXeKVBLD5KOr2uAa0nOCz8F\nzi9aZjZwSjPrbgiMJ7njykKSIPwG6JrOryPptZ8HfAZcmi5f2PH2BCv3rq9NEtr3SQ7fZwJHFMw/\nh+SwfCkwrqD9ZJK9+mKSMeMfAnYumL9Xuq2FwJ9JQr6mjrdlrNy7fjHwCcmh+u3AKSQjqjbNH01y\nhPPfaf2NwJ1At6LtHpoutyh9v58E9kvn9UxfN+qONw/kWEGSngReDiG05tzSrE18uG4WOYe8snzY\nZBXnw3WzyHlPbhY5h9wscg65WeQccrPIOeRmkXPIzSLnkJtFziE3i5xDbha5/wc7H1Q1d1OMswAA\nAABJRU5ErkJggg==\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0x10eb8d6d8>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "from mlxtend.plotting import plot_confusion_matrix\n",
    "\n",
    "fig, ax = plot_confusion_matrix(conf_mat=cm)\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## API"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "## confusion_matrix\n",
      "\n",
      "*confusion_matrix(y_target, y_predicted, binary=False, positive_label=1)*\n",
      "\n",
      "Compute a confusion matrix/contingency table.\n",
      "\n",
      "**Parameters**\n",
      "\n",
      "- `y_target` : array-like, shape=[n_samples]\n",
      "\n",
      "    True class labels.\n",
      "\n",
      "- `y_predicted` : array-like, shape=[n_samples]\n",
      "\n",
      "    Predicted class labels.\n",
      "\n",
      "- `binary` : bool (default: False)\n",
      "\n",
      "    Maps a multi-class problem onto a\n",
      "    binary confusion matrix, where\n",
      "    the positive class is 1 and\n",
      "    all other classes are 0.\n",
      "\n",
      "- `positive_label` : int (default: 1)\n",
      "\n",
      "    Class label of the positive class.\n",
      "\n",
      "**Returns**\n",
      "\n",
      "- `mat` : array-like, shape=[n_classes, n_classes]\n",
      "\n",
      "\n",
      "**Examples**\n",
      "\n",
      "For usage examples, please see\n",
      "    [http://rasbt.github.io/mlxtend/user_guide/evaluate/confusion_matrix/](http://rasbt.github.io/mlxtend/user_guide/evaluate/confusion_matrix/)\n",
      "\n",
      "\n"
     ]
    }
   ],
   "source": [
    "with open('../../api_modules/mlxtend.evaluate/confusion_matrix.md', 'r') as f:\n",
    "    s = f.read() \n",
    "print(s)"
   ]
  }
 ],
 "metadata": {
  "anaconda-cloud": {},
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.5"
  },
  "toc": {
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": true,
   "toc_window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
